package cn.com.wangluotongxin.linux.controller;

import cn.com.wangluotongxin.common.web.AjaxResult;
import cn.com.wangluotongxin.linux.form.SendCommandForm;
import cn.com.wangluotongxin.linux.service.ICommandService;
import cn.com.wangluotongxin.linux.vo.CommandResultVo;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "CMD COMMAND")
@RestController
@RequestMapping("/command")
public class CommandController {

    @Autowired
    private ICommandService commandService;

    @ApiOperation("指令执行")
    @PostMapping("/send")
    public AjaxResult<CommandResultVo> send(@RequestBody SendCommandForm form) {
        Assert.isTrue(StrUtil.isNotBlank(form.getCommand()), "缺少指令");
        Assert.isTrue(StrUtil.isNotBlank(form.getFolderPath()), "缺少指令目录");

        return AjaxResult.success( commandService.sendCommand(form));
    }
}
